1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.orekit.files.ccsds;
19
20 import java.util.AbstractList;
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.LinkedHashSet;
25 import java.util.List;
26 import java.util.ListIterator;
27 import java.util.Set;
28
29 import org.hipparchus.geometry.euclidean.threed.Vector3D;
30 import org.hipparchus.linear.RealMatrix;
31 import org.hipparchus.util.Pair;
32 import org.orekit.errors.OrekitException;
33 import org.orekit.errors.OrekitMessages;
34 import org.orekit.files.general.OrbitFile;
35 import org.orekit.files.general.SatelliteInformation;
36 import org.orekit.files.general.SatelliteTimeCoordinate;
37 import org.orekit.frames.Frame;
38 import org.orekit.frames.LOFType;
39 import org.orekit.orbits.CartesianOrbit;
40 import org.orekit.time.AbsoluteDate;
41
42
43
44
45
46
47
48
49 public class OEMFile extends ODMFile {
50
51
52 private List<EphemeridesBlock> ephemeridesBlocks;
53
54
55 public OEMFile() {
56 ephemeridesBlocks = new ArrayList<EphemeridesBlock>();
57 }
58
59
60 void addEphemeridesBlock() {
61 ephemeridesBlocks.add(new EphemeridesBlock());
62 }
63
64
65
66
67 public List<EphemeridesBlock> getEphemeridesBlocks() {
68 return Collections.unmodifiableList(ephemeridesBlocks);
69 }
70
71
72
73
74 void checkTimeSystems() throws OrekitException {
75 final OrbitFile.TimeSystem timeSystem = getEphemeridesBlocks().get(0).getMetaData().getTimeSystem();
76 for (final EphemeridesBlock block : ephemeridesBlocks) {
77 if (!timeSystem.equals(block.getMetaData().getTimeSystem())) {
78 throw new OrekitException(OrekitMessages.CCSDS_OEM_INCONSISTENT_TIME_SYSTEMS,
79 timeSystem, block.getMetaData().getTimeSystem());
80 }
81 }
82 }
83
84
85
86
87
88
89 @Override
90 public String getCoordinateSystem() {
91 return ephemeridesBlocks.get(0).getMetaData().getFrame().toString();
92 }
93
94
95 @Override
96 public OrbitFile.TimeSystem getTimeSystem() {
97 return ephemeridesBlocks.get(0).getMetaData().getTimeSystem();
98 }
99
100
101
102
103
104
105 @Override
106 public AbsoluteDate getEpoch() {
107 return ephemeridesBlocks.get(0).getStartTime();
108 }
109
110
111 @Override
112 public Collection<SatelliteInformation> getSatellites() {
113 final Set<String> availableSatellites = getAvailableSatelliteIds();
114 final List<SatelliteInformation> satellites =
115 new ArrayList<SatelliteInformation>(availableSatellites.size());
116 for (String satId : availableSatellites) {
117 satellites.add(new SatelliteInformation(satId));
118 }
119 return satellites;
120 }
121
122
123 @Override
124 public int getSatelliteCount() {
125 return getAvailableSatelliteIds().size();
126 }
127
128
129 @Override
130 public SatelliteInformation getSatellite(final String satId) {
131 final Set<String> availableSatellites = getAvailableSatelliteIds();
132 if (availableSatellites.contains(satId)) {
133 return new SatelliteInformation(satId);
134 } else {
135 return null;
136 }
137 }
138
139
140 @Override
141 public List<SatelliteTimeCoordinate> getSatelliteCoordinates(final String satId) {
142
143
144
145 final List<Pair<Integer, Integer>> ephemeridesBlockMapping = new ArrayList<Pair<Integer, Integer>>();
146 final ListIterator<EphemeridesBlock> it = ephemeridesBlocks.listIterator();
147 int totalDataLines = 0;
148 while (it.hasNext()) {
149 final int index = it.nextIndex();
150 final EphemeridesBlock block = it.next();
151
152 if (block.getMetaData().getObjectID().equals(satId)) {
153 final int dataLines = block.getEphemeridesDataLines().size();
154 totalDataLines += dataLines;
155 ephemeridesBlockMapping.add(new Pair<Integer, Integer>(index, dataLines));
156 }
157 }
158
159
160 final int totalNumberOfCoordinates = totalDataLines;
161
162 return new AbstractList<SatelliteTimeCoordinate>() {
163
164 @Override
165 public SatelliteTimeCoordinate get(final int index) {
166 if (index < 0 || index >= size()) {
167 throw new IndexOutOfBoundsException();
168 }
169
170
171 int ephemeridesBlockIndex = -1;
172 int dataLineIndex = index;
173 for (Pair<Integer, Integer> pair : ephemeridesBlockMapping) {
174 if (dataLineIndex < pair.getValue()) {
175 ephemeridesBlockIndex = pair.getKey();
176 break;
177 } else {
178 dataLineIndex -= pair.getValue();
179 }
180 }
181
182 if (ephemeridesBlockIndex == -1 || dataLineIndex == -1) {
183 throw new IndexOutOfBoundsException();
184 }
185
186 final EphemeridesDataLine dataLine =
187 ephemeridesBlocks.get(ephemeridesBlockIndex).getEphemeridesDataLines().get(dataLineIndex);
188 final CartesianOrbit orbit = dataLine.getOrbit();
189 return new SatelliteTimeCoordinate(orbit.getDate(), orbit.getPVCoordinates());
190 }
191
192 @Override
193 public int size() {
194 return totalNumberOfCoordinates;
195 }
196
197 };
198 }
199
200
201
202
203 private Set<String> getAvailableSatelliteIds() {
204 final Set<String> availableSatellites = new LinkedHashSet<String>();
205 for (EphemeridesBlock block : ephemeridesBlocks) {
206 availableSatellites.add(block.getMetaData().getObjectID());
207 }
208 return availableSatellites;
209 }
210
211
212
213
214
215
216
217 public class EphemeridesBlock {
218
219
220 private ODMMetaData metaData;
221
222
223
224 private AbsoluteDate startTime;
225
226
227
228 private AbsoluteDate stopTime;
229
230
231
232 private AbsoluteDate useableStartTime;
233
234
235
236 private AbsoluteDate useableStopTime;
237
238
239 private String interpolationMethod;
240
241
242 private int interpolationDegree;
243
244
245 private List<EphemeridesDataLine> ephemeridesDataLines;
246
247
248 private List<CovarianceMatrix> covarianceMatrices;
249
250
251 private boolean hasRefFrameEpoch;
252
253
254
255 private List<String> ephemeridesDataLinesComment;
256
257
258 public EphemeridesBlock() {
259 metaData = new ODMMetaData(OEMFile.this);
260 ephemeridesDataLines = new ArrayList<EphemeridesDataLine>();
261 covarianceMatrices = new ArrayList<CovarianceMatrix>();
262 }
263
264
265
266
267 public List<EphemeridesDataLine> getEphemeridesDataLines() {
268 return ephemeridesDataLines;
269 }
270
271
272
273
274 public List<CovarianceMatrix> getCovarianceMatrices() {
275 return covarianceMatrices;
276 }
277
278
279
280
281 public ODMMetaData getMetaData() {
282 return metaData;
283 }
284
285
286
287
288
289 public AbsoluteDate getStartTime() {
290 return startTime;
291 }
292
293
294
295
296
297 void setStartTime(final AbsoluteDate startTime) {
298 this.startTime = startTime;
299 }
300
301
302
303
304
305 public AbsoluteDate getStopTime() {
306 return stopTime;
307 }
308
309
310
311
312
313 void setStopTime(final AbsoluteDate stopTime) {
314 this.stopTime = stopTime;
315 }
316
317
318
319
320
321 public AbsoluteDate getUseableStartTime() {
322 return useableStartTime;
323 }
324
325
326
327
328
329 void setUseableStartTime(final AbsoluteDate useableStartTime) {
330 this.useableStartTime = useableStartTime;
331 }
332
333
334
335
336
337 public AbsoluteDate getUseableStopTime() {
338 return useableStopTime;
339 }
340
341
342
343
344
345 void setUseableStopTime(final AbsoluteDate useableStopTime) {
346 this.useableStopTime = useableStopTime;
347 }
348
349
350
351
352 public String getInterpolationMethod() {
353 return interpolationMethod;
354 }
355
356
357
358
359 void setInterpolationMethod(final String interpolationMethod) {
360 this.interpolationMethod = interpolationMethod;
361 }
362
363
364
365
366 public int getInterpolationDegree() {
367 return interpolationDegree;
368 }
369
370
371
372
373 void setInterpolationDegree(final int interpolationDegree) {
374 this.interpolationDegree = interpolationDegree;
375 }
376
377
378
379
380
381 public boolean getHasRefFrameEpoch() {
382 return hasRefFrameEpoch;
383 }
384
385
386
387
388 void setHasRefFrameEpoch(final boolean hasRefFrameEpoch) {
389 this.hasRefFrameEpoch = hasRefFrameEpoch;
390 }
391
392
393
394
395 public List<String> getEphemeridesDataLinesComment() {
396 return ephemeridesDataLinesComment;
397 }
398
399
400
401
402 void setEphemeridesDataLinesComment(final List<String> ephemeridesDataLinesComment) {
403 this.ephemeridesDataLinesComment = new ArrayList<String>(ephemeridesDataLinesComment);
404 }
405 }
406
407
408
409
410
411
412 public static class EphemeridesDataLine {
413
414
415 private CartesianOrbit orbit;
416
417
418 private Vector3D acceleration;
419
420
421
422
423
424 EphemeridesDataLine(final CartesianOrbit orbit, final Vector3D acceleration) {
425 this.acceleration = acceleration;
426 this.orbit = orbit;
427 }
428
429
430
431
432 public CartesianOrbit getOrbit() {
433 return orbit;
434 }
435
436
437
438
439 public Vector3D getAcceleration() {
440 return acceleration;
441 }
442
443 }
444
445
446
447
448
449 public static class CovarianceMatrix {
450
451
452 private RealMatrix matrix;
453
454
455 private AbsoluteDate epoch;
456
457
458 private LOFType lofType;
459
460
461
462 private Frame frame;
463
464
465
466
467
468
469
470 CovarianceMatrix(final AbsoluteDate epoch,
471 final LOFType lofType, final Frame frame,
472 final RealMatrix lastMatrix) {
473 this.matrix = lastMatrix;
474 this.epoch = epoch;
475 this.lofType = lofType;
476 this.frame = frame;
477 }
478
479
480
481
482 public RealMatrix getMatrix() {
483 return matrix;
484 }
485
486
487
488
489 public AbsoluteDate getEpoch() {
490 return epoch;
491 }
492
493
494
495
496
497
498
499
500
501
502
503 public LOFType getLofType() {
504 return lofType;
505 }
506
507
508
509
510
511
512
513
514
515 public Frame getFrame() {
516 return frame;
517 }
518
519 }
520
521
522 }